#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
nginxurl=/opt/openresty/nginx
. $nginxurl/scripts/golo.conf
ip=$RTKIP
port="3333"
(sleep 1;echo "UNLOGALL ICOM3";\
		sleep 1;echo "log NTRIPCONFIG ONCE "; \
			sleep 2)|telnet $ip $port |grep coolcar0 |awk -F "IN:" '{print $1}' >/tmp/rtkport.txt
rtknum=$(cat /tmp/rtkport.txt|grep 2101 |wc -l)
if [ $rtknum == 1 ];then
   sudo sed -i "s/2101/9101/" /tmp/rtkport.txt && sudo sed -i "s/NCOM1/NTRIPCONFIG NCOM1/" /tmp/rtkport.txt && sudo sed -i "s/Coolcar@pass0/Coolcar@pass0 ALL/" /tmp/rtkport.txt
   else
  sudo sed -i "s/9101/2101/" /tmp/rtkport.txt && sudo sed -i "s/NCOM1/NTRIPCONFIG NCOM1/" /tmp/rtkport.txt  && sudo sed -i "s/Coolcar@pass0/Coolcar@pass0 ALL/" /tmp/rtkport.txt
    fi
    ntripncom1=$(sudo cat /tmp/rtkport.txt |grep  coolcar0) 
(sleep 1;echo "UNLOGALL ICOM3"; \
		sleep 1;echo "$ntripncom1" ; \
			sleep 2;echo "SAVECONFIG";sleep 1; echo reset)|telnet $ip $port

